package net.jlibrary.parking.action;

import javax.annotation.Resource;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import net.jlibrary.common.core.entity.Pagination;
import net.jlibrary.common.core.entity.PaginationParam;
import net.jlibrary.parking.action.vo.ParkingVo;
import net.jlibrary.parking.service.IParkingManager;

@RequestMapping("/parking")
@RestController
public class ParkingAction {

	@Resource
	IParkingManager parkingMapper;

	// view
	@RequestMapping(value = "/parkingView", method = { RequestMethod.GET })
	public ModelAndView modelAndView() {
		return new ModelAndView("/parking/parkingView");
	}

	// 查询车场列表
	@RequestMapping(value = "/selectParkingList", method = { RequestMethod.POST })
	public Pagination parkListMap(ParkingVo parkingVo, PaginationParam param) {
		Pagination pagination = parkingMapper.listsPage(parkingVo, param);
		return pagination;
	}

	// 表单初始化信息
	@RequestMapping(value = "/parkingFormInit", method = { RequestMethod.GET })
	public ParkingVo parkingFormInit() {
		ParkingVo parkingVo = new ParkingVo();
		return parkingVo;
	}

	// 保存信息
	@RequestMapping(value = "/saveParking", method = { RequestMethod.POST })
	public ModelMap saveParking(@ModelAttribute("vm") ParkingVo vo) {
		parkingMapper.save(vo);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}

	// 详情信息
	@RequestMapping(value = "/detailParking", method = { RequestMethod.GET })
	public ParkingVo detailParking(ParkingVo vo) {
		vo = parkingMapper.get(vo);
		return vo;
	}

	// 删除信息
	@RequestMapping(value = "/deleteParking", method = { RequestMethod.POST })
	public ModelMap deleteParking(Long id) {
		ParkingVo parkingVo = new ParkingVo();
		parkingVo.setId(id);
		parkingMapper.delete(parkingVo);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}

	// 修改信息
	@RequestMapping(value = "/updateParking", method = { RequestMethod.POST })
	public ModelMap updateParking(@ModelAttribute("vm") ParkingVo parkingVo) {
		parkingMapper.update(parkingVo);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}

}
